import request from '@/plugins/request'
import { getItem, getToken } from '@/plugins/auth'
import { isNotEmpty } from '@/plugins'

export function getEmployeeList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getEmployeeList',
    method: 'post',
    data: data
  })
}

export function getInstrumentCommandDefineList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-weixing/getInstrumentCommandDefineList',
    method: 'post',
    data: data
  })
}

export function getInstrumentButtonDefineList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-weixing/getInstrumentButtonDefineList',
    method: 'post',
    data: data
  })
}

export function getPaperList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-paper/getPaperList',
    method: 'post',
    data: data
  })
}

export function getPaperAuthorList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-paper/getPaperAuthorList',
    method: 'post',
    data: data
  })
}

export function getMagazineList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-paper/getMagazineList',
    method: 'post',
    data: data
  })
}

export function getMeetingList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-paper/getMeetingList',
    method: 'post',
    data: data
  })
}

export function getFunctionListByRoleID(roleID, token) {
  const data = JSON.parse(getItem('baseParam'))
  // if (isNotEmpty(token)) {
  //   data.token = token
  // }
  data.resultArray = 'pagePrivilege,function.functionID.ID-name-shortName-parentID-functionURL-cssText-programType-jumpType-orderSeq-pagePrivilege-isLock'
  data.parameterArray += (',roleID=' + roleID)
  return request({
    url: '/cloud-system/getRoleFunctionList',
    method: 'post',
    data: data
  })
}

export function getUserRoleList(token, userID) {
  const data = JSON.parse(getItem('baseParam'))
  // if (isNotEmpty(token)) {
  //   data.token = token
  // }
  data.resultArray = 'roleID,organizationID,role.roleID.name-systemDefineID-orderSeq-roleType,applicationID,organization.organizationID.name'
  data.parameterArray += (',userID=' + (isNotEmpty(userID) ? userID : localStorage.getItem("userId")))
  return request({
    url: '/cloud-system/getRoleUserList',
    method: 'post',
    data: data
  })
}

export function getRoleList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getRoleList',
    method: 'post',
    data: data
  })
}

export function getRoleFunctionList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getRoleFunctionList',
    method: 'post',
    data: data
  })
}

export function getResearchProjectList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-paper/getResearchProjectList',
    method: 'post',
    data: data
  })
}

export function getPagePrivilegeDefineList(result) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getPagePrivilegeDefineList',
    method: 'post',
    data: data
  })
}

/**
 * 获取操作权限
 * @param functionID 菜单ID
 * @returns PagePrivilege
 */
export function getPermission(functionID) {
  return request({
    url: '/cloud-system/getOneFunctionDetail',
    method: 'post',
    data: { token: getToken(), ID: functionID }
  })
}

export function getJobList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getJobList',
    method: 'post',
    data: data
  })
}

export function getCategoryList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getCategoryList',
    method: 'post',
    data: data
  })
}

export function getFunctionList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getFunctionList',
    method: 'post',
    data: data
  })
}

export function getArticleList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getArticleList',
    method: 'post',
    data: data
  })
}

export function getManufacturerList() {
  return request({
    url: '/cloud-system/getManufacturerList',
    method: 'post',
    data: JSON.parse(getItem('baseParam'))
  })
}

export function getBrandList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getBrandList',
    method: 'post',
    data: data
  })
}

export function getInstrumentPanelDefine(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-weixing/getInstrumentPanelDefineList',
    method: 'post',
    data: data
  })
}

export function getInstrumentPanelButtonList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-weixing/getInstrumentPanelButtonList',
    method: 'post',
    data: data
  })
}

export function getModelList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getModelList',
    method: 'post',
    data: data
  })
}

export function getModelListByBrandID(brandID) {
  const data = JSON.parse(getItem('baseParam'))
  data.parameterArray += (',brandID=' + brandID)
  data.resultArray += ',code'
  return request({
    url: '/cloud-system/getModelList',
    method: 'post',
    data: data
  })
}

export function getApplicationList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getApplicationList',
    method: 'post',
    data: data
  })
}

export function getSystemDefineList() {
  const data = JSON.parse(getItem('baseParam'))
  return request({
    url: '/cloud-system/getSystemDefineList',
    method: 'post',
    data: data
  })
}

export function getParameterList() {
  const data = JSON.parse(getItem('baseParam'))
  return request({
    url: '/cloud-system/getParameterList',
    method: 'post',
    data: data
  })
}

export function getCityList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getCityList',
    method: 'post',
    data: data
  })
}

export function getNavigatorList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getNavigatorList',
    method: 'post',
    data: data
  })
}

export function getSiteList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getSiteList',
    method: 'post',
    data: data
  })
}

export function getFileServerList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getFileServerList',
    method: 'post',
    data: data
  })
}

export function getFileFolderList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getFileFolderList',
    method: 'post',
    data: data
  })
}

export function getOrganizationList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getOrganizationList',
    method: 'post',
    data: data
  })
}

export function getUserList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getUserList',
    method: 'post',
    data: data
  })
}

export function getDepartmentList(parameter) {
  const data = JSON.parse(getItem('baseParam'))
  data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  return request({
    url: '/cloud-system/getDepartmentList',
    method: 'post',
    data: data
  })
}

export function getObjectDefineList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getObjectDefineList',
    method: 'post',
    data: data
  })
}

export function getFieldDefineList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  // data.orderArray = 'orderSeq=1'
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getFieldDefineList',
    method: 'post',
    data: data
  })
}

export function getObjectList(cloudName, objectDefineShortName) {
  const data = JSON.parse(getItem('baseParam'))
  return request({
    url: '/cloud-' + cloudName + '/get' + (objectDefineShortName.charAt(0).toUpperCase() + objectDefineShortName.slice(1)) + 'List',
    method: 'post',
    data: data
  })
}

export function getMessageList(parameter, result) {
  const data = JSON.parse(getItem('baseParam'))
  if (isNotEmpty(parameter)) {
    data.parameterArray += (',' + parameter)
  }
  if (isNotEmpty(result)) {
    data.resultArray += (',' + result)
  }
  return request({
    url: '/cloud-system/getMessageList',
    method: 'post',
    data: data
  })
}

